import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { configParams } from '../storage-config';

@Injectable({
  providedIn: 'root'
})
export class StorageWarehousOrderService {

  headers = configParams.headers;

  serviceUrls: any = {
    queryWarehousingListUrl: '/warehousing/list', // 查询入库单list
    deleteWarehousUrl: '/warehousing/delete', // 入库单 - 删除
    queryWarehousingDetailstUrl: '/warehousingDetails/list', // 入库单详情
    addWarehousOrderUrl: '/warehousing/save', // 入库单 - 新增
    updateWarehousOrderUrl: '/warehousing/update', // 入库单 - 修改
    warehousNullifyUrl: '/warehousingDetails/nullify', // 入库单 - 作废
    judgeSnInfoUrl: '/warehousingDetails/operationSn', // 入库处理 - sn信息判断
  };

  constructor(public httpClient: HttpClient) { }

  // 查询入库单list
  getWarehousingList(params: any) {
    return this.httpClient.post(this.serviceUrls.queryWarehousingListUrl, params, {headers: this.headers}).toPromise();
  }

  // 入库单 - 删除
  deleteWarehousingData(params: any) {
    return this.httpClient.post(this.serviceUrls.deleteWarehousUrl, params, {headers: this.headers}).toPromise();
  }

  // 查询入库单详情
  getWarehousingDetails(params: any) {
    return this.httpClient.post(this.serviceUrls.queryWarehousingDetailstUrl, params, {headers: this.headers}).toPromise();
  }

  /**
   * 入库单 - 新增 \ 编辑
   * @param params 
   * @param type 0：新增 1：编辑
   * @returns 
   */
  editWarehousOrderData(params: any, type: 0 | 1) {
    let url = type === 0 ? this.serviceUrls.addWarehousOrderUrl : this.serviceUrls.updateWarehousOrderUrl;
    return this.httpClient.post(url, params, {headers: this.headers}).toPromise();
  }

  // 入库单 - 作废
  warehousNullifyData(params: any) {
    return this.httpClient.post(this.serviceUrls.warehousNullifyUrl, params, {headers: this.headers}).toPromise();
  }

  // 入库处理 - SN信息判断
  judgeSnInfoData(params: any) {
    return this.httpClient.post(this.serviceUrls.judgeSnInfoUrl, params, {headers: this.headers}).toPromise();
  }
}



